import 'package:flutter/cupertino.dart';
import 'package:hitutor/UI/NoticeAndMessage/ItemNotice.dart';
import 'package:hitutor/Util/HttpGo.dart';
import 'package:hitutor/Util/PageUtil.dart';
import 'package:hitutor/Widget/MyDialog.dart';
import 'package:hitutor/Widget/MyPage.dart';

import 'DialogReadNotice.dart';

class NewMessageList extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _NewMessageList();
  }
}

class _NewMessageList extends State<NewMessageList> {
  List<dynamic> informationList = [];

  getInformationList() {
    HttpGo(context).get("/Information/GetInformationList", {}, (data) {
      informationList = data["informationList"];
      setState(() {});
    }, (code, error) {
      showToast(error);
    }, showLoading: true);
  }

  @override
  void initState() {
    getInformationList();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MyPage(
        "最新消息",
        Container(
            child: ListView.builder(
                itemCount: informationList.length,
                itemBuilder: (BuildContext context, int index) {
                  return ItemMessage(informationList[index], onTap: () {
                    // showWidgetDialog(context, DialogReadNotice(index == 0));
                    if ((informationList[index]["url"] ?? "").isNotEmpty) PageUtil().launchURL(informationList[index]["url"]);
                  });
                })));
  }
}
